﻿/********************************************************************************************
 * 文件名称:    
 * 设计人员:    许志伟
 * 设计时间:    
 * 功能描述:   

 * 注意事项:    
 *      
 * 版权所有:    Copyright (c) 2015, Fujian Calvin
 * 
 * 修改记录:    修改时间        人员        修改备注
 *              ----------      ------      -------------------------------------------------
 *                           
 * ********************************************************************************************/

using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Web;
using NPOI;
using NPOI.HPSF;
using NPOI.HSSF;
using NPOI.HSSF.UserModel;
using NPOI.POIFS;
using NPOI.Util;
using NPOI.HSSF.Util;
using NPOI.HSSF.Extractor;
using System.Web.UI.HtmlControls;
using NPOI.SS.UserModel;
using NPOI.HSSF.Record.CF;
using NPOI.SS.Util;

namespace Calvin.Utilities.Excel操作
{
    public class ExcelUtilityNoCom
    {
        public static HSSFWorkbook workbook;
        public enum LinkType
        {
            网址,
            档案,
            邮件,
            内文
        };
        public static void InitializeWorkbook()
        {
            ////create a entry of DocumentSummaryInformation
            if (workbook == null)
                workbook = new HSSFWorkbook();
            //HSSFFont font1 = workbook.CreateFont();
            //HSSFCellStyle Style = workbook.CreateCellStyle();
            //font1.FontHeightInPoints = 10;
            //font1.FontName = "新细明体";
            //Style.SetFont(font1);
            //for (int i = 0; i < workbook.NumberOfSheets; i++)
            //{
            //    HSSFSheet Sheets = workbook.GetSheetAt(0);
            //    for (int k = Sheets.FirstRowNum; k <= Sheets.LastRowNum; k++)
            //    {
            //        HSSFRow row = Sheets.GetRow(k);
            //        for (int l = row.FirstCellNum; l < row.LastCellNum; l++)
            //        {
            //            HSSFCell Cell = row.GetCell(l);
            //            Cell.CellStyle = Style;
            //        }
            //    }
            //}
            DocumentSummaryInformation dsi = PropertySetFactory.CreateDocumentSummaryInformation();
            dsi.Company = "Sirc";
            workbook.DocumentSummaryInformation = dsi;
            ////create a entry of SummaryInformation
            SummaryInformation si = PropertySetFactory.CreateSummaryInformation();
            si.Subject = "";
            si.Title = "";
            si.Author = "Sirc";
            si.Comments = "";
            workbook.SummaryInformation = si;
        }
        public static HSSFWorkbook InitializeWorkbook(HSSFWorkbook Workbook)
        {
            ////create a entry of DocumentSummaryInformation
            if (Workbook == null)
            {
                Workbook = new HSSFWorkbook();
            }
            DocumentSummaryInformation dsi = PropertySetFactory.CreateDocumentSummaryInformation();
            dsi.Company = "Sirc";
            Workbook.DocumentSummaryInformation = dsi;
            ////create a entry of SummaryInformation
            SummaryInformation si = PropertySetFactory.CreateSummaryInformation();
            si.Subject = "";
            si.Title = "";
            si.Author = "Sirc";
            si.Comments = "";
            Workbook.SummaryInformation = si;
            return Workbook;

        }
        #region Excel档案信息及相关应用
        public static string GetCellPosition(int row, int col)
        {
            col = Convert.ToInt32('A') + col;
            row = row + 1;
            return ((char)col) + row.ToString();
        }
        #endregion

        #region 比特流(stream)应用及与workbook转换
        public static void WriteStreamToFile(MemoryStream ms, string FileName)
        {
            FileStream fs = new FileStream(FileName, FileMode.Create, FileAccess.Write);
            byte[] data = ms.ToArray();

            fs.Write(data, 0, data.Length);
            fs.Flush();
            fs.Close();

            data = null;
            ms = null;
            fs = null;
        }
        public static void WriteStreamToFile(byte[] data, string FileName)
        {
            FileStream fs = new FileStream(FileName, FileMode.Create, FileAccess.Write);
            fs.Write(data, 0, data.Length);
            fs.Flush();
            fs.Close();
            data = null;
            fs = null;
        }
        public static Stream WorkBookToStream(HSSFWorkbook InputWorkBook)
        {
            MemoryStream ms = new MemoryStream();
            InputWorkBook.Write(ms);
            ms.Flush();
            ms.Position = 0;
            return ms;
        }
        public static void WorkBookToFile(HSSFWorkbook InputWorkBook, string FileName)
        {
            FileStream fs = new FileStream(FileName, FileMode.Create, FileAccess.Write);
            InputWorkBook.Write(fs);
            fs.Flush();
            fs.Close();
            fs = null;
        
        }
        public static HSSFWorkbook StreamToWorkBook(Stream InputStream)
        {
            HSSFWorkbook WorkBook = new HSSFWorkbook(InputStream);
            return WorkBook;
        }
        public static HSSFWorkbook MemoryStreamToWorkBook(MemoryStream InputStream)
        {
            HSSFWorkbook WorkBook = new HSSFWorkbook(InputStream as Stream);
            return WorkBook;
        }
        public static HSSFWorkbook FileToWorkBook(string FileFullPath)
        {
            FileStream stream = new FileStream(FileFullPath, FileMode.Open);
            HSSFWorkbook WorkBook = new HSSFWorkbook(stream as Stream);
            return WorkBook;
        }

      
        public static Stream FileToStream(string FileName)
        {
            FileInfo fi = new FileInfo(FileName);
            if (fi.Exists == true)
            {
                FileStream fs = new FileStream(FileName, FileMode.Open, FileAccess.Read);
                return fs;
            }
            else return null;
        }
        public static Stream MemoryStreamToStream(MemoryStream ms)
        {
            return ms as Stream;
        }
        #endregion

        #region 创建空白档案

        /// <summary>
        /// 建立空白excel档到比特流.
        /// </summary>
        /// <param name="SheetName">Name of the sheet.</param>
        /// <returns></returns>
        public static Stream CreateEmptyFile(params string[] SheetName)
        {
            MemoryStream ms = new MemoryStream();
            workbook = new HSSFWorkbook();
            InitializeWorkbook();
            if (SheetName == null)
            {
                workbook.CreateSheet();
            }
            else
            {
                foreach (string temp in SheetName)
                {
                    workbook.CreateSheet(temp);
                }
            }
            workbook.Write(ms);
            ms.Flush();
            return ms;
        }
        /// <summary>
        /// 建立空白excel档到档案.
        /// </summary>
        /// <param name="FileName">Name of the file.</param>
        /// <param name="SheetName">Name of the sheet.</param>
        public static void CreateEmptyFile(string FileName, params string[] SheetName)
        {
            MemoryStream ms = CreateEmptyFile(SheetName) as MemoryStream;
            WriteStreamToFile(ms, FileName);
        }
        #endregion

        #region DataTable与Excel互相转换
        /// <summary>
        /// 插入datatable到WorkBook
        /// </summary>
        /// <param name="SourceTable">源table</param>
        /// <param name="Workbook">excel工作区</param>
        /// <param name="StartRowIndex">EXCEL开始的插入行 </param>
        /// <param name="StartColIndex">EXCEL开始的插入列</param>
        /// <param name="IsFormHeader">是否构建表头</param>
        /// <returns></returns>
        public static HSSFWorkbook RenderDataTableToWorkBook(DataTable SourceTable, HSSFWorkbook Workbook, int StartRowIndex, int StartColIndex,int SheetIndex=0,Boolean IsFormHeaderRow=true)
        {
            Workbook = InitializeWorkbook(Workbook);

            HSSFSheet sheet = Workbook.GetSheetAt(SheetIndex) as HSSFSheet;
            if (sheet == null)
            {
                sheet = (HSSFSheet)Workbook.CreateSheet();
            }
            if (IsFormHeaderRow)
            {
                ICellStyle headerStyle = Workbook.CreateCellStyle();
                headerStyle.Alignment = HorizontalAlignment.Center;
                IFont headerFont = Workbook.CreateFont();
                headerFont.FontName = "宋体";

                headerFont.Boldweight = (short)NPOI.SS.UserModel.FontBoldWeight.Bold;
                headerFont.FontHeightInPoints = 12;
                headerStyle.SetFont(headerFont);
                HSSFRow headerRow = (HSSFRow)sheet.CreateRow(StartRowIndex);
                // handling header.
                foreach (DataColumn column in SourceTable.Columns)
                {
                    ICell cell = headerRow.CreateCell(column.Ordinal + StartColIndex);
                    cell.SetCellValue(column.ColumnName);
                    cell.CellStyle = headerStyle;
                }
            }
            // handling value.
            int rowIndex = (IsFormHeaderRow ? 1 : 0 )+ StartRowIndex;
            foreach (DataRow row in SourceTable.Rows)
            {
                HSSFRow dataRow = (HSSFRow)sheet.CreateRow(rowIndex);

                foreach (DataColumn column in SourceTable.Columns)
                {
                    dataRow.CreateCell(column.Ordinal + StartColIndex).SetCellValue(row[column].ToString());
                }

                rowIndex++;
            }
            return Workbook;
        }
        /// <summary>
        /// 将DataTable数据输出成档案.
        /// </summary>
        /// <param name="SourceTable">The source table.</param>
        /// <param name="FileName">Name of the file.</param>
        /// <param name="StartRowIndex">开始索引</param>
        public static void RenderDataTableToExcel(string FileName, DataTable SourceTable, int StartRowIndex, int StartColIndex, int SheetIndex = 0, Boolean IsFormHeaderRow = true)
        {
            HSSFWorkbook Workbook = InitializeWorkbook(new HSSFWorkbook());
            Workbook = RenderDataTableToWorkBook(SourceTable, Workbook, StartRowIndex, StartColIndex, SheetIndex, IsFormHeaderRow);
            WorkBookToFile(Workbook, FileName);
        }
        /// <summary>
        /// 从比特流读取数据到DataTable.
        /// </summary>
        /// <param name="ExcelFileStream">The excel file stream.</param>
        /// <param name="SheetName">Name of the sheet.</param>
        /// <param name="HeaderRowIndex">Index of the header row.</param>
        /// <param name="HaveHeader">if set to <c>true</c> [have header].</param>
        /// <returns></returns>
        public static DataTable RenderDataTableFromExcel(Stream ExcelFileStream, string SheetName, int HeaderRowIndex, bool HaveHeader)
        {
            workbook = new HSSFWorkbook(ExcelFileStream);
            InitializeWorkbook();
            HSSFSheet sheet = (HSSFSheet)workbook.GetSheet(SheetName);

            DataTable table = new DataTable();

            HSSFRow headerRow = (HSSFRow)sheet.GetRow(HeaderRowIndex);
            int cellCount = headerRow.LastCellNum;

            for (int i = headerRow.FirstCellNum; i < cellCount; i++)
            {
                string ColumnName = (HaveHeader == true) ? headerRow.GetCell(i).StringCellValue : "f" + i.ToString();
                DataColumn column = new DataColumn(ColumnName);
                table.Columns.Add(column);
            }

            int rowCount = sheet.LastRowNum;
            int RowStart = (HaveHeader == true) ? sheet.FirstRowNum + 1 : sheet.FirstRowNum;
            for (int i = RowStart; i <= sheet.LastRowNum; i++)
            {
                HSSFRow row = (HSSFRow)sheet.GetRow(i);
                DataRow dataRow = table.NewRow();

                for (int j = row.FirstCellNum; j < cellCount; j++)
                    dataRow[j] = row.GetCell(j).ToString();
            }

            ExcelFileStream.Close();
            workbook = null;
            sheet = null;
            return table;
        }

        /// <summary>
        /// 从比特流读取数据到DataTable.
        /// </summary>
        /// <param name="ExcelFileStream">The excel file stream.</param>
        /// <param name="SheetIndex">Index of the sheet.</param>
        /// <param name="HeaderRowIndex">Index of the header row.</param>
        /// <param name="HaveHeader">if set to <c>true</c> [have header].</param>
        /// <returns></returns>
        public static DataTable RenderDataTableFromExcel(Stream ExcelFileStream, int SheetIndex, int HeaderRowIndex, bool HaveHeader)
        {
            //switch (cell.CellType)
            //{
            //    case HSSFCellType.BLANK:
            //        dr[i] = "[null]";
            //        break;
            //    case HSSFCellType.BOOLEAN:
            //        dr[i] = cell.BooleanCellValue;
            //        break;
            //    case HSSFCellType.NUMERIC:
            //        dr[i] = cell.ToString();    //This is a trick to get the correct value of the cell. NumericCellValue will return a numeric value no matter the cell value is a date or a number.
            //        break;
            //    case HSSFCellType.STRING:
            //        dr[i] = cell.StringCellValue;
            //        break;
            //    case HSSFCellType.ERROR:
            //        dr[i] = cell.ErrorCellValue;
            //        break;
            //    case HSSFCellType.FORMULA:
            //    default:
            //        dr[i] = "=" + cell.CellFormula;
            //        break;
            //}
            workbook = new HSSFWorkbook(ExcelFileStream);
            InitializeWorkbook();
            HSSFSheet sheet = (HSSFSheet)workbook.GetSheetAt(SheetIndex);

            DataTable table = new DataTable();

            HSSFRow headerRow = (HSSFRow)sheet.GetRow(HeaderRowIndex);
            int cellCount = headerRow.LastCellNum;

            for (int i = headerRow.FirstCellNum; i < cellCount; i++)
            {
                string ColumnName = (HaveHeader == true) ? headerRow.GetCell(i).ToString() : "f" + i.ToString();
                DataColumn column = new DataColumn(ColumnName);
                table.Columns.Add(column);
            }

            int rowCount = sheet.LastRowNum;
            int RowStart = (HaveHeader == true) ? sheet.FirstRowNum + 1 : sheet.FirstRowNum;
            for (int i = RowStart; i <= sheet.LastRowNum; i++)
            {
                HSSFRow row = (HSSFRow)sheet.GetRow(i);
                DataRow dataRow = table.NewRow();

                for (int j = row.FirstCellNum; j < cellCount; j++)
                {
                    if (row.GetCell(j) != null)
                        dataRow[j] = row.GetCell(j).ToString();
                }

                table.Rows.Add(dataRow);
            }

            ExcelFileStream.Close();
            workbook = null;
            sheet = null;
            return table;
        }
        #endregion


        #region 超链接
        /// <summary>
        /// 在比特流单元格中建立超链接.
        /// </summary>
        /// <param name="InputStream">The input stream.</param>
        /// <param name="SheetNameOrIndex">Index of the sheet name or.</param>
        /// <param name="LinkName">Name of the link.</param>
        /// <param name="LinkValueOrIndex">Index of the link value or.</param>
        /// <param name="s1">The s1.</param>
        /// <param name="RowIndex">Index of the row.</param>
        /// <param name="CellIndex">Index of the cell.</param>
        /// <returns></returns>
        public static Stream MakeLink(Stream InputStream, string SheetNameOrIndex, string LinkName, string LinkValueOrIndex, LinkType s1, int RowIndex, int CellIndex)
        {

            workbook = new HSSFWorkbook(InputStream);
            //HSSFSheet sheet = hssfworkbook.CreateSheet("Hyperlinks");
            ////cell style for hyperlinks
            ////by default hyperlinks are blue and underlined        
            InitializeWorkbook();
            MemoryStream ms = new MemoryStream();
            HSSFCellStyle hlink_style = workbook.CreateCellStyle() as HSSFCellStyle;
            HSSFFont hlink_font = workbook.CreateFont() as HSSFFont;
            hlink_font.Underline = FontUnderlineType.Single;
            hlink_font.Color = HSSFColor.Blue.Index;
            hlink_style.SetFont(hlink_font);
            string ResultLinkValue = string.Empty;
            int ResultSheet;
            HSSFSheet sheet;
            if (int.TryParse(SheetNameOrIndex, out ResultSheet) == true)
                sheet = workbook.GetSheetAt(ResultSheet) as HSSFSheet;
            else
                sheet = workbook.GetSheet(SheetNameOrIndex) as HSSFSheet;
            HSSFCell cell = sheet.CreateRow(RowIndex).CreateCell(CellIndex) as HSSFCell;
            cell.SetCellValue(LinkName);
            HSSFHyperlink link;
            switch (s1.ToString())
            {
                case "网址": link = new HSSFHyperlink(HyperlinkType.Url);
                    ResultLinkValue = string.Copy(LinkValueOrIndex);
                    break;
                case "档案": link = new HSSFHyperlink(HyperlinkType.File);
                    ResultLinkValue = string.Copy(LinkValueOrIndex);
                    break;
                case "邮件": link = new HSSFHyperlink(HyperlinkType.Email);
                    // ResultLinkValue = string.Copy(LinkValue);   
                    ResultLinkValue = "mailto:" + LinkValueOrIndex;
                    break;
                case "内文":
                    int result;
                    link = new HSSFHyperlink(HyperlinkType.Document);
                    if (int.TryParse(LinkValueOrIndex, out result) == true)
                        ResultLinkValue = "'" + workbook.GetSheetName(result) + "'!A1";
                    else
                        ResultLinkValue = "'" + LinkValueOrIndex + "'!A1";
                    break;
                default: link = new HSSFHyperlink(HyperlinkType.Url);
                    break;
            }
            link.Address = (ResultLinkValue);
            cell.Hyperlink = (link);
            cell.CellStyle = (hlink_style);
            workbook.Write(ms);
            ms.Flush();
            return ms;
        }
        /// <summary>
        /// 在档案单元格中建立超链接.
        /// </summary>
        /// <param name="FileName">Name of the file.</param>
        /// <param name="InputStream">The input stream.</param>
        /// <param name="SheetNameOrIndex">Index of the sheet name or.</param>
        /// <param name="LinkName">Name of the link.</param>
        /// <param name="LinkValueOrIndex">Index of the link value or.</param>
        /// <param name="s1">The s1.</param>
        /// <param name="RowIndex">Index of the row.</param>
        /// <param name="CellIndex">Index of the cell.</param>
        public static void MakeLink(string FileName, Stream InputStream, string SheetNameOrIndex, string LinkName, string LinkValueOrIndex, LinkType s1, int RowIndex, int CellIndex)
        {
            MemoryStream ms = MakeLink(InputStream, SheetNameOrIndex, LinkName, LinkValueOrIndex, s1, RowIndex, CellIndex) as MemoryStream;
            WriteStreamToFile(ms, FileName);
        }
        /// <summary>
        /// 建立新比特流并在单元格中建立超链接.
        /// </summary>
        /// <param name="SheetNameOrIndex">Index of the sheet name or.</param>
        /// <param name="LinkName">Name of the link.</param>
        /// <param name="LinkValueOrIndex">Index of the link value or.</param>
        /// <param name="s1">The s1.</param>
        /// <param name="RowIndex">Index of the row.</param>
        /// <param name="CellIndex">Index of the cell.</param>
        /// <returns></returns>
        public static Stream MakeLinkFromEmpty(string SheetNameOrIndex, string LinkName, string LinkValueOrIndex, LinkType s1, int RowIndex, int CellIndex)
        {

            workbook = new HSSFWorkbook();
            HSSFSheet sheet1 = workbook.CreateSheet() as HSSFSheet;
            //HSSFSheet sheet = hssfworkbook.CreateSheet("Hyperlinks");
            ////cell style for hyperlinks
            ////by default hyperlinks are blue and underlined        
            InitializeWorkbook();
            MemoryStream ms = new MemoryStream();
            HSSFCellStyle hlink_style = workbook.CreateCellStyle() as HSSFCellStyle;
            HSSFFont hlink_font = workbook.CreateFont() as HSSFFont;
            hlink_font.Underline = FontUnderlineType.Single;
            hlink_font.Color = HSSFColor.Blue.Index;
            hlink_style.SetFont(hlink_font);
            string ResultLinkValue = string.Empty;
            int ResultSheet;
            HSSFSheet sheet;
            if (int.TryParse(SheetNameOrIndex, out ResultSheet) == true)
                sheet = workbook.GetSheetAt(ResultSheet) as HSSFSheet;
            else
                sheet = workbook.GetSheet(SheetNameOrIndex) as HSSFSheet;
            HSSFCell cell = sheet.CreateRow(RowIndex).CreateCell(CellIndex) as HSSFCell;
            cell.SetCellValue(LinkName);
            HSSFHyperlink link;
            switch (s1.ToString())
            {
                case "网址": link = new HSSFHyperlink(HyperlinkType.Url);
                    ResultLinkValue = string.Copy(LinkValueOrIndex);
                    break;
                case "档案": link = new HSSFHyperlink(HyperlinkType.File);
                    ResultLinkValue = string.Copy(LinkValueOrIndex);
                    break;
                case "邮件": link = new HSSFHyperlink(HyperlinkType.Email);
                    // ResultLinkValue = string.Copy(LinkValue);   
                    ResultLinkValue = "mailto:" + LinkValueOrIndex;
                    break;
                case "内文":
                    int result;
                    link = new HSSFHyperlink(HyperlinkType.Document);
                    if (int.TryParse(LinkValueOrIndex, out result) == true)
                        ResultLinkValue = "'" + workbook.GetSheetName(result) + "'!A1";
                    else
                        ResultLinkValue = "'" + LinkValueOrIndex + "'!A1";
                    break;
                default: link = new HSSFHyperlink(HyperlinkType.Url);
                    break;
            }
            link.Address = (ResultLinkValue);
            cell.Hyperlink = (link);
            cell.CellStyle = (hlink_style);
            workbook.Write(ms);
            ms.Flush();
            return ms;
        }
        /// <summary>
        /// 建立新档案并在单元格中建立超链接.
        /// </summary>
        /// <param name="FileName">Name of the file.</param>
        /// <param name="SheetNameOrIndex">Index of the sheet name or.</param>
        /// <param name="LinkName">Name of the link.</param>
        /// <param name="LinkValueOrIndex">Index of the link value or.</param>
        /// <param name="s1">The s1.</param>
        /// <param name="RowIndex">Index of the row.</param>
        /// <param name="CellIndex">Index of the cell.</param>
        public static void MakeLinkFromEmpty(string FileName, string SheetNameOrIndex, string LinkName, string LinkValueOrIndex, LinkType s1, int RowIndex, int CellIndex)
        {
            MemoryStream ms = MakeLinkFromEmpty(SheetNameOrIndex, LinkName, LinkValueOrIndex, s1, RowIndex, CellIndex) as MemoryStream;
            WriteStreamToFile(ms, FileName);
        }
        #endregion

        #region 设定字体字形



        public static HSSFCellStyle SetCellStyle(HSSFFont InputFont)
        {
            InitializeWorkbook();
            HSSFCellStyle style1 = workbook.CreateCellStyle() as HSSFCellStyle;
            style1.SetFont(InputFont);
            return style1;
        }

        public static HSSFCellStyle CreateCellStyle(HSSFWorkbook Workbook)
        {
            HSSFCellStyle style1 = Workbook.CreateCellStyle() as HSSFCellStyle;
            return style1;
        }
        /// <summary>
        /// 设置字体
        /// </summary>
        /// <param name="HSSFCellStyle">HSSFCellStyle已有的cell的style</param>
        /// <param name="WorkBook">文档</param>
        /// <param name="FontName">字体名称</param>
        /// <param name="FontSize">字体大小</param>
        /// <param name="FontColor">字体颜色</param>
        /// <param name="FontUnderlineType">下划线类别</param>
        /// <returns>HSSFCellStyle</returns>
        public static HSSFCellStyle SetCellFontStyle(HSSFCellStyle Style1, HSSFWorkbook WorkBook, String FontName, short FontSize, HSSFColor FontColor, FontUnderlineType FontUnderlineType)
        {
            IFont font = WorkBook.CreateFont();
            font.Color = FontColor.Indexed;
            font.FontHeightInPoints = FontSize;
            font.FontName = FontName;
            font.Underline=FontUnderlineType;
            Style1.SetFont(font);
            return Style1;
        }
        /// <summary>
        /// 设置边框
        /// </summary>
        /// <param name="Style1">HSSFCellStyle已有的cell的style</param>
        /// <param name="WorkBook">文档</param>
        /// <param name="BorderTopStyle">上边框样式</param>
        /// <param name="BorderTopColor">下边框颜色</param>
        /// <param name="BorderRightStyle"></param>
        /// <param name="BorderRightColor"></param>
        /// <param name="BorderBottomStyle"></param>
        /// <param name="BorderBottomColor"></param>
        /// <param name="BorderLeftStyle"></param>
        /// <param name="BorderLeftColor"></param>
        /// <returns>HSSFCellStyle</returns>
        public static HSSFCellStyle SetCellBorder(HSSFCellStyle Style1, HSSFWorkbook WorkBook, BorderStyle BorderTopStyle, HSSFColor BorderTopColor,
            BorderStyle BorderRightStyle, HSSFColor BorderRightColor,
            BorderStyle BorderBottomStyle,HSSFColor BorderBottomColor,
             BorderStyle BorderLeftStyle,HSSFColor BorderLeftColor
            )
        {
   
            Style1.BorderTop = BorderTopStyle;
            Style1.TopBorderColor = BorderTopColor.Indexed;
            Style1.BorderRight = BorderRightStyle;
            Style1.RightBorderColor = BorderRightColor.Indexed;
            Style1.BorderBottom = BorderBottomStyle;
            Style1.BottomBorderColor = BorderBottomColor.Indexed;
            Style1.BorderLeft = BorderLeftStyle;
            Style1.LeftBorderColor = BorderLeftColor.Indexed;
            return Style1;
        }
        /// <summary>
        /// 设定字体颜色大小到比特流.
        /// </summary>
        /// <param name="InputStream">The input stream.</param>
        /// <param name="FontName">Name of the font.</param>
        /// <param name="FontSize">Size of the font.</param>
        /// <param name="IsAllSheet">if set to <c>true</c> [is all sheet].</param>
        /// <param name="SheetName">Name of the sheet.</param>
        /// <returns></returns>
        public static Stream ApplyStyleToFile(Stream InputStream, string FontName, short FontSize, bool IsAllSheet, params string[] SheetName)
        {
            workbook = new HSSFWorkbook(InputStream);
            InitializeWorkbook();
            HSSFFont font = workbook.CreateFont() as HSSFFont;
            HSSFCellStyle Style = workbook.CreateCellStyle() as HSSFCellStyle;
            font.FontHeightInPoints = FontSize;
            font.FontName = FontName;
            Style.SetFont(font);
            MemoryStream ms = new MemoryStream();
            int i;
            if (IsAllSheet == true)
            {
                for (i = 0; i < workbook.NumberOfSheets; i++)
                {
                    HSSFSheet Sheets = workbook.GetSheetAt(0) as HSSFSheet;
                    for (int k = Sheets.FirstRowNum; k <= Sheets.LastRowNum; k++)
                    {
                        HSSFRow row = Sheets.GetRow(k) as HSSFRow;
                        for (int l = row.FirstCellNum; l < row.LastCellNum; l++)
                        {
                            HSSFCell Cell = row.GetCell(l) as HSSFCell;
                            Cell.CellStyle = Style;
                        }
                    }
                }
            }
            else
            {
                for (i = 0; i < SheetName.Length; i++)
                {
                    HSSFSheet Sheets = workbook.GetSheet(SheetName[i]) as HSSFSheet;
                    for (int k = Sheets.FirstRowNum; k <= Sheets.LastRowNum; k++)
                    {
                        HSSFRow row = Sheets.GetRow(k) as HSSFRow;
                        for (int l = row.FirstCellNum; l < row.LastCellNum; l++)
                        {
                            HSSFCell Cell = row.GetCell(l) as HSSFCell;
                            Cell.CellStyle = Style;
                        }
                    }
                }
            }
            workbook.Write(ms);
            ms.Flush();
            return ms;
        }
        /// <summary>
        /// 设定字体颜色大小到比特流.
        /// </summary>
        /// <param name="InputStream">The input stream.</param>
        /// <param name="FontName">Name of the font.</param>
        /// <param name="FontSize">Size of the font.</param>
        /// <param name="IsAllSheet">if set to <c>true</c> [is all sheet].</param>
        /// <param name="SheetIndex">Index of the sheet.</param>
        /// <returns></returns>
        public static Stream ApplyStyleToFile(Stream InputStream, string FontName, short FontSize, bool IsAllSheet, params int[] SheetIndex)
        {
            workbook = new HSSFWorkbook(InputStream);
            InitializeWorkbook();
            MemoryStream ms = new MemoryStream();
            HSSFFont font = workbook.CreateFont() as HSSFFont;
            HSSFCellStyle Style = workbook.CreateCellStyle() as HSSFCellStyle;
            font.FontHeightInPoints = FontSize;
            font.FontName = FontName;
            Style.SetFont(font);
            int i;
            if (IsAllSheet == true)
            {
                for (i = 0; i < workbook.NumberOfSheets; i++)
                {
                    HSSFSheet Sheets = workbook.GetSheetAt(0) as HSSFSheet;
                    for (int k = Sheets.FirstRowNum; k <= Sheets.LastRowNum; k++)
                    {
                        HSSFRow row = Sheets.GetRow(k) as HSSFRow;
                        for (int l = row.FirstCellNum; l < row.LastCellNum; l++)
                        {
                            HSSFCell Cell = row.GetCell(l) as HSSFCell;
                            Cell.CellStyle = Style;
                        }
                    }
                }
            }
            else
            {
                for (i = 0; i < SheetIndex.Length; i++)
                {
                    HSSFSheet Sheets = workbook.GetSheetAt(SheetIndex[i]) as HSSFSheet;
                    for (int k = Sheets.FirstRowNum; k <= Sheets.LastRowNum; k++)
                    {
                        HSSFRow row = Sheets.GetRow(k) as HSSFRow;
                        for (int l = row.FirstCellNum; l < row.LastCellNum; l++)
                        {
                            HSSFCell Cell = row.GetCell(l) as HSSFCell;
                            Cell.CellStyle = Style;
                        }
                    }
                }
            }
            workbook.Write(ms);
            ms.Flush();
            return ms;
        }
        /// <summary>
        /// 设定字体颜色大小到档案.
        /// </summary>
        /// <param name="FileName">Name of the file.</param>
        /// <param name="InputStream">The input stream.</param>
        /// <param name="FontName">Name of the font.</param>
        /// <param name="FontSize">Size of the font.</param>
        /// <param name="IsAllSheet">if set to <c>true</c> [is all sheet].</param>
        /// <param name="SheetName">Name of the sheet.</param>
        public static void ApplyStyleToFile(string FileName, Stream InputStream, string FontName, short FontSize, bool IsAllSheet, params string[] SheetName)
        {
            MemoryStream ms = ApplyStyleToFile(InputStream, FontName, FontSize, IsAllSheet, SheetName) as MemoryStream;
            WriteStreamToFile(ms, FileName);
        }
        /// <summary>
        /// 设定字体颜色大小到档案.
        /// </summary>
        /// <param name="FileName">Name of the file.</param>
        /// <param name="InputStream">The input stream.</param>
        /// <param name="FontName">Name of the font.</param>
        /// <param name="FontSize">Size of the font.</param>
        /// <param name="IsAllSheet">if set to <c>true</c> [is all sheet].</param>
        /// <param name="SheetIndex">Index of the sheet.</param>
        public static void ApplyStyleToFile(string FileName, Stream InputStream, string FontName, short FontSize, bool IsAllSheet, params int[] SheetIndex)
        {
            MemoryStream ms = ApplyStyleToFile(InputStream, FontName, FontSize, IsAllSheet, SheetIndex) as MemoryStream;
            WriteStreamToFile(ms, FileName);
        }
        #endregion


        #region 设定网格线
        /// <summary>
        /// 设定网格线到比特流.
        /// </summary>
        /// <param name="InputSteam">The input steam.</param>
        /// <param name="haveGridLine">if set to <c>true</c> [have grid line].</param>
        /// <param name="SheetName">Name of the sheet.</param>
        /// <returns></returns>
        public static Stream SetGridLine(Stream InputSteam, bool haveGridLine, params string[] SheetName)
        {
            workbook = new HSSFWorkbook(InputSteam);
            InitializeWorkbook();
            MemoryStream ms = new MemoryStream();
            if (SheetName == null)
            {
                for (int i = 0; i < workbook.NumberOfSheets; i++)
                {
                    HSSFSheet s1 = workbook.GetSheetAt(i) as HSSFSheet;
                    s1.DisplayGridlines = haveGridLine;
                }
            }
            else
            {
                foreach (string TempSheet in SheetName)
                {
                    HSSFSheet s1 = workbook.GetSheet(TempSheet) as HSSFSheet;
                    s1.DisplayGridlines = haveGridLine;
                }
            }
            workbook.Write(ms);
            ms.Flush();
            return ms;
        }
        /// <summary>
        /// 设定网格线到比特流.
        /// </summary>
        /// <param name="InputSteam">The input steam.</param>
        /// <param name="haveGridLine">if set to <c>true</c> [have grid line].</param>
        /// <param name="SheetIndex">Index of the sheet.</param>
        /// <returns></returns>
        public static Stream SetGridLine(Stream InputSteam, bool haveGridLine, params int[] SheetIndex)
        {
            workbook = new HSSFWorkbook(InputSteam);
            InitializeWorkbook();
            MemoryStream ms = new MemoryStream();
            if (SheetIndex == null)
            {
                for (int i = 0; i < workbook.NumberOfSheets; i++)
                {
                    HSSFSheet s1 = workbook.GetSheetAt(i) as HSSFSheet;
                    s1.DisplayGridlines = haveGridLine;
                }
            }
            else
            {
                foreach (int TempSheet in SheetIndex)
                {
                    HSSFSheet s1 = workbook.GetSheetAt(TempSheet) as HSSFSheet;
                    s1.DisplayGridlines = haveGridLine;
                }
            }
            workbook.Write(ms);
            ms.Flush();
            return ms;
        }
        /// <summary>
        /// 设定网格线到档案.
        /// </summary>
        /// <param name="FileName">Name of the file.</param>
        /// <param name="InputSteam">The input steam.</param>
        /// <param name="haveGridLine">if set to <c>true</c> [have grid line].</param>
        /// <param name="SheetIndex">Index of the sheet.</param>
        public static void SetGridLine(string FileName, Stream InputSteam, bool haveGridLine, params int[] SheetIndex)
        {
            MemoryStream ms = SetGridLine(InputSteam, haveGridLine, SheetIndex) as MemoryStream;
            WriteStreamToFile(ms, FileName);
        }
        /// <summary>
        /// 设定网格线到档案.
        /// </summary>
        /// <param name="FileName">Name of the file.</param>
        /// <param name="InputSteam">The input steam.</param>
        /// <param name="haveGridLine">if set to <c>true</c> [have grid line].</param>
        /// <param name="SheetName">Name of the sheet.</param>
        public static void SetGridLine(string FileName, Stream InputSteam, bool haveGridLine, params string[] SheetName)
        {
            MemoryStream ms = SetGridLine(InputSteam, haveGridLine, SheetName) as MemoryStream;
            WriteStreamToFile(ms, FileName);
        }
        #endregion

        #region 撷取字符串从excel档案
        /// <summary>
        /// 从比特流将数据转成字符串输出
        /// </summary>
        /// <param name="InputStream">The input stream.</param>
        /// <returns></returns>
        public static string ExtractStringFromFileStream(Stream InputStream)
        {
            HSSFWorkbook HBook = new HSSFWorkbook(InputStream);
            ExcelExtractor extractor = new ExcelExtractor(HBook);
            return extractor.Text;
        }
        /// <summary>
        /// 从档案将数据转成字符串输出
        /// </summary>
        /// <param name="FileName">Name of the file.</param>
        /// <returns></returns>
        public static string ExtractStringFromFileStream(string FileName)
        {
            FileInfo fi = new FileInfo(FileName);
            if (fi.Exists == true)
            {
                using (FileStream fs = fi.Open(FileMode.Open))
                {
                    HSSFWorkbook HBook = new HSSFWorkbook(fs);
                    ExcelExtractor extractor = new ExcelExtractor(HBook);
                    return extractor.Text;
                }
            }
            else return null;
        }
        #endregion

        #region 设定群组
        /// <summary>
        /// 设定群组到比特流.
        /// </summary>
        /// <param name="SheetName">Name of the sheet.</param>
        /// <param name="IsRow">if set to <c>true</c> [is row].</param>
        /// <param name="From">From.</param>
        /// <param name="End">The end.</param>
        /// <returns></returns>
        public static Stream CreateGroup(string SheetName, bool IsRow, int From, int End)
        {
            MemoryStream ms = new MemoryStream();
            workbook = new HSSFWorkbook();
            InitializeWorkbook();
            HSSFSheet sh = (HSSFSheet)workbook.CreateSheet(SheetName);
            for (int i = 0; i <= End; i++)
            {
                sh.CreateRow(i);
            }
            if (IsRow == true)
                sh.GroupRow(From, End);
            else
                sh.GroupColumn((short)From, (short)End);

            workbook.Write(ms);
            ms.Flush();
            return ms;

        }
        /// <summary>
        /// 建立群组到档案.
        /// </summary>
        /// <param name="FileName">Name of the file.</param>
        /// <param name="SheetName">Name of the sheet.</param>
        /// <param name="IsRow">if set to <c>true</c> [is row].</param>
        /// <param name="From">From.</param>
        /// <param name="End">The end.</param>
        public static void CreateGroup(string FileName, string SheetName, bool IsRow, int From, int End)
        {
            MemoryStream ms = CreateGroup(SheetName, IsRow, From, End) as MemoryStream;
            WriteStreamToFile(ms, FileName);
        }
        #endregion

        #region 从模板建立档案
        /// <summary>
        /// 从样板建立HSSFWorkbook
        /// </summary>
        /// <param name="TemplateFileName">模板名称</param>
        /// <returns>HSSFWorkbook</returns>
        public static HSSFWorkbook CreateWorkbookFromTemplate(string TemplateFileName)
        {
            FileInfo fi = new FileInfo(TemplateFileName);
            HSSFWorkbook WorkBook = null;
            if (fi.Exists == true)
            {
                FileStream file = new FileStream(TemplateFileName, FileMode.Open, FileAccess.Read);
                WorkBook = new HSSFWorkbook(file);
                DocumentSummaryInformation dsi = PropertySetFactory.CreateDocumentSummaryInformation();
                dsi.Company = "Sirc";
                WorkBook.DocumentSummaryInformation = dsi;
                ////create a entry of SummaryInformation
                SummaryInformation si = PropertySetFactory.CreateSummaryInformation();
                si.Subject = "";
                si.Title = "";
                si.Author = "Sirc";
                si.Comments = "";
                WorkBook.SummaryInformation = si;
                return WorkBook;
            }
            return null;
        }
        /// <summary>
        /// 从样板建立比特流.
        /// </summary>
        /// <param name="TemplateFileName">Name of the template file.</param>
        /// <returns></returns>
        public static Stream CreateFileStreamFromTemplate(string TemplateFileName)
        {
            HSSFWorkbook WorkBook = CreateWorkbookFromTemplate(TemplateFileName);
            if (WorkBook != null)
            {
                MemoryStream ms = new MemoryStream();
                WorkBook.Write(ms);
                return ms;
            }
            return null;
        }

        /// <summary>
        /// 从样板建立档案.
        /// </summary>
        /// <param name="TemplateFileName">Name of the template file.</param>
        /// <param name="OutputFileName">Name of the output file.</param>
        public static void CreateFileFromTemplate(string TemplateFileName, string OutputFileName)
        {
            FileInfo fi = new FileInfo(TemplateFileName);
            if (fi.Exists == true)
            {
                MemoryStream ms = CreateFileStreamFromTemplate(TemplateFileName) as MemoryStream;
                WriteStreamToFile(ms, OutputFileName);
            }
            //else ;
        }
        #endregion

        #region 嵌入图片
        /// <summary>
        /// Loads the image.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <param name="wb">The wb.</param>
        /// <returns></returns>
        public static int LoadImage(string path, HSSFWorkbook wb)
        {
            FileStream file = new FileStream(path, FileMode.Open, FileAccess.Read);
            byte[] buffer = new byte[file.Length];
            file.Read(buffer, 0, (int)file.Length);
            return wb.AddPicture(buffer, PictureType.JPEG);

        }
        /// <summary>
        /// 嵌入图片到比特流.
        /// </summary>
        /// <param name="InputStream">The input stream.</param>
        /// <param name="SheetIndex">Index of the sheet.</param>
        /// <param name="PicFileName">Name of the pic file.</param>
        /// <param name="IsOriginalSize">if set to <c>true</c> [is original size].</param>
        /// <param name="RowPosition">The row position.</param>
        /// <returns></returns>
        public static Stream EmbedImage(Stream InputStream, int SheetIndex, string PicFileName, bool IsOriginalSize, int[] RowPosition)
        {
            workbook = new HSSFWorkbook(InputStream);
            InitializeWorkbook();
            MemoryStream ms = new MemoryStream();
            HSSFSheet sheet1 = workbook.GetSheetAt(SheetIndex) as HSSFSheet;
            HSSFPatriarch patriarch = sheet1.CreateDrawingPatriarch() as HSSFPatriarch;
            //create the anchor
            HSSFClientAnchor anchor;
            anchor = new HSSFClientAnchor(0, 0, 0, 0,
                RowPosition[0], RowPosition[1], RowPosition[2], RowPosition[3]);
            anchor.AnchorType = 2;
            //load the picture and get the picture index in the workbook
            HSSFPicture picture = patriarch.CreatePicture(anchor, LoadImage(PicFileName, workbook)) as HSSFPicture;
            //Reset the image to the original size.
            if (IsOriginalSize == true)
                picture.Resize();
            //Line Style
            picture.LineStyle = LineStyle.None;
            workbook.Write(ms);
            ms.Flush();
            return ms;
        }
        /// <summary>
        /// 嵌入图片到档案.
        /// </summary>
        /// <param name="FileName">Name of the file.</param>
        /// <param name="SheetIndex">Index of the sheet.</param>
        /// <param name="InputStream">The input stream.</param>
        /// <param name="PicFileName">Name of the pic file.</param>
        /// <param name="IsOriginalSize">if set to <c>true</c> [is original size].</param>
        /// <param name="RowPosition">The row position.</param>
        public static void EmbedImage(string FileName, int SheetIndex, Stream InputStream, string PicFileName, bool IsOriginalSize, int[] RowPosition)
        {
            MemoryStream ms = EmbedImage(InputStream, SheetIndex, PicFileName, IsOriginalSize, RowPosition) as MemoryStream;
            WriteStreamToFile(ms, FileName);
        }
        /// <summary>
        /// 建立新比特流并嵌入图片.
        /// </summary>
        /// <param name="PicFileName">Name of the pic file.</param>
        /// <param name="IsOriginalSize">if set to <c>true</c> [is original size].</param>
        /// <param name="RowPosition">The row position.</param>
        /// <returns></returns>
        public static Stream EmbedImage(string PicFileName, bool IsOriginalSize, int[] RowPosition)
        {
            /*
             * dx1 第1个单元格中x轴的偏移量 dy1 第1个单元格中y轴的偏移量 
dx2 第2个单元格中x轴的偏移量，最大值1023 dy2 第2个单元格中y轴的偏移量，
             * 最大值255 col1 第1个单元格的列号 row1 第1个单元格的行号 c
             * ol2 第2个单元格的列号 row2 第2个单元格的行号
             * 
             * dx2:第二个单元格的开始X坐标
dy2:第二个单元格的开始y坐标
            因为HSSFClientAnchor中dx只能在0-1023之间,dy只能在0-255之间，所以这里采用比例的方式
col1 - the column (0 based); of the first cell.
row1 - the row (0 based); of the first cell.
col2 - the column (0 based); of the second cell.
row2 - the row (0 based); of the second cell.
col1 图片的左上角放在第几个列cell， 
row1 图片的左上角放在第几个行cell， 

col2 图片的右下角放在第几个列cell， 
row2 图片的右下角放在第几个行cell，
列宽   
sheet.setColumnWidth((short)column,(short)width); 
行高 
row.setHeight((short)height);
添加多个图片时:多个pic应该share同一个DrawingPatriarch在同一个sheet里面*/
            workbook = new HSSFWorkbook();
            InitializeWorkbook();
            MemoryStream ms = new MemoryStream();
            HSSFSheet sheet1 = workbook.CreateSheet() as HSSFSheet;
            HSSFPatriarch patriarch = sheet1.CreateDrawingPatriarch() as HSSFPatriarch;
            //create the anchor
            HSSFClientAnchor anchor;
            anchor = new HSSFClientAnchor(0, 0, 0, 0,
                RowPosition[0], RowPosition[1], RowPosition[2], RowPosition[3]);
            anchor.AnchorType = 2;
            //load the picture and get the picture index in the workbook
            HSSFPicture picture = patriarch.CreatePicture(anchor, LoadImage(PicFileName, workbook)) as HSSFPicture;
            //Reset the image to the original size.
            if (IsOriginalSize == true)
                picture.Resize();
            //Line Style
            picture.LineStyle = LineStyle.None;
            workbook.Write(ms);
            ms.Flush();
            return ms;
        }
        /// <summary>
        /// 建立新档案并嵌入图片.
        /// </summary>
        /// <param name="ExcelFileName">Name of the excel file.</param>
        /// <param name="PicFileName">Name of the pic file.</param>
        /// <param name="IsOriginalSize">if set to <c>true</c> [is original size].</param>
        /// <param name="RowPosition">The row position.</param>
        public static void EmbedImage(string ExcelFileName, string PicFileName, bool IsOriginalSize, int[] RowPosition)
        {
            MemoryStream ms = EmbedImage(PicFileName, IsOriginalSize, RowPosition) as MemoryStream;
            WriteStreamToFile(ms, ExcelFileName);
        }
        #endregion

        #region 合并单元格
        /// <summary>
        /// 合并单元格于比特流.
        /// </summary>
        /// <param name="InputStream">The input stream.</param>
        /// <param name="SheetIndex">Index of the sheet.</param>
        /// <param name="RowFrom">The row from.</param>
        /// <param name="ColumnFrom">The column from.</param>
        /// <param name="RowTo">The row to.</param>
        /// <param name="ColumnTo">The column to.</param>
        /// <returns></returns>
        public static void MergeCell(HSSFWorkbook Workbook, int RowFrom, int ColumnFrom, int RowTo, int ColumnTo, int SheetIndex = 0)
        {
            Workbook = InitializeWorkbook(Workbook);
            MemoryStream ms = new MemoryStream();
            InitializeWorkbook();
            HSSFSheet sheet1 = Workbook.GetSheetAt(SheetIndex) as HSSFSheet;
            sheet1.AddMergedRegion(new Region(RowFrom, ColumnFrom, RowTo, ColumnTo));
        }
        #endregion

        #region 设定单元格公式
        /// <summary>
        /// 设定单元格公式于比特流.
        /// </summary>
        /// <param name="InputStream">The input stream.</param>
        /// <param name="SheetIndex">Index of the sheet.</param>
        /// <param name="Formula">The formula.</param>
        /// <param name="RowIndex">Index of the row.</param>
        /// <param name="ColumnIndex">Index of the column.</param>
        /// <returns></returns>
        public static Stream SetFormula(Stream InputStream, int SheetIndex, string Formula, int RowIndex, int ColumnIndex)
        {
            //here, we must insert at least one sheet to the workbook. otherwise, Excel will say 'data lost in file'
            //So we insert three sheet just like what Excel does
            workbook = new HSSFWorkbook(InputStream);
            InitializeWorkbook();
            MemoryStream ms = new MemoryStream();
            HSSFSheet sheet1 = workbook.GetSheetAt(SheetIndex) as HSSFSheet;
            sheet1.CreateRow(RowIndex).CreateCell(ColumnIndex).SetCellFormula(Formula);
            workbook.Write(ms);
            ms.Flush();
            return ms;
        }
        /// <summary>
        /// 设定单元格公式于档案.
        /// </summary>
        /// <param name="FileName">Name of the file.</param>
        /// <param name="InputStream">The input stream.</param>
        /// <param name="SheetIndex">Index of the sheet.</param>
        /// <param name="Formula">The formula.</param>
        /// <param name="RowIndex">Index of the row.</param>
        /// <param name="ColumnIndex">Index of the column.</param>
        public static void SetFormula(string FileName, Stream InputStream, int SheetIndex, string Formula, int RowIndex, int ColumnIndex)
        {
            MemoryStream ms = SetFormula(InputStream, SheetIndex, Formula, RowIndex, ColumnIndex) as MemoryStream;
            WriteStreamToFile(ms, FileName);
        }
        /// <summary>
        /// 建立新比特流并设定单元格公式.
        /// </summary>
        /// <param name="Formula">The formula.</param>
        /// <param name="RowIndex">Index of the row.</param>
        /// <param name="ColumnIndex">Index of the column.</param>
        /// <returns></returns>
        public static Stream SetFormula(string Formula, int RowIndex, int ColumnIndex)
        {
            //here, we must insert at least one sheet to the workbook. otherwise, Excel will say 'data lost in file'
            //So we insert three sheet just like what Excel does
            workbook = new HSSFWorkbook();
            InitializeWorkbook();
            MemoryStream ms = new MemoryStream();
            HSSFSheet sheet1 = workbook.CreateSheet() as HSSFSheet;
            sheet1.CreateRow(RowIndex).CreateCell(ColumnIndex).SetCellFormula(Formula);
            workbook.Write(ms);
            ms.Flush();
            return ms;
        }
        /// <summary>
        /// 建立新档案并设定单元格公式.
        /// </summary>
        /// <param name="FileName">Name of the file.</param>
        /// <param name="Formula">The formula.</param>
        /// <param name="RowIndex">Index of the row.</param>
        /// <param name="ColumnIndex">Index of the column.</param>
        public static void SetFormula(string FileName, string Formula, int RowIndex, int ColumnIndex)
        {
            MemoryStream ms = SetFormula(Formula, RowIndex, ColumnIndex) as MemoryStream;
            WriteStreamToFile(ms, FileName);
        }
        #endregion


    }
}




